package com.woniuxy.usercoachassemble.commons;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;

/**
 * ClassName: EmailUtils
 * Description: 短信工具类
 * date: 2020/7/9 10:58
 *
 * @author woniuxy
 */
@Component
public class EmailUtils {
    // 邮箱发件人
    private  static final  String from ="fy961057101@163.com";
    @Autowired
    private JavaMailSender mailSender;

    // 魔板引擎
    @Autowired
    TemplateEngine templateEngine;

    /**
     * params 1.to 发送邮箱的地址 2. subject 发送的邮件标题 3.veriCode 邮件正文
     */
    public void sendMail(String to, String subject, String verifyCode) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(verifyCode);
        try {


            mailSender.send(message);
            //logger.info("简单邮件已经发送。");
        } catch (Exception e) {
            //logger.error("发送简单邮件时发生异常！", e);
            e.printStackTrace();
        }

    }
}
